package com.ocm.commerceinteraction.ui;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.ocm.commerceinteraction.MainActivity;
import com.ocm.commerceinteraction.R;
import com.ocm.commerceinteraction.model.CenterMessage;
import com.ocm.commerceinteraction.ui.adapter.MessageListAdapter;
import com.ocm.commerceinteraction.util.helper.DBHelper;
import com.ocm.commerceinteraction.util.helper.LogHelper;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

@EFragment(R.layout.fragment_meaage)
public class MeaageFragment extends BaseFragment {


    @ViewById(R.id.toptitle_title)
    TextView topTitle;

    @ViewById(R.id.listview_applay)
    ListView applyListView;

//    @ViewById(R.id.listview_notify)
//    ListView notifyListView;

    MessageListAdapter applyListAdapter;
    MessageListAdapter notifyListAdapter;

    @Override
    @AfterViews
    void initView() {
        topTitle.setText("申请与通知");
        loadData();
    }
    List<CenterMessage> centerMessageList;
    List<CenterMessage> applyList = new ArrayList<>();
    List<CenterMessage> notifyList = new ArrayList<>();
    void loadData() {
        centerMessageList = DBHelper.getCenterMsg();
        if (centerMessageList == null) {
            return;
        }
        for (int i = 0; i < centerMessageList.size(); i++) {
            //1 删除好友 2 好友添加请求 3同意好友添加请求
            // 4拒绝了好友添加请求 5邀请加入某群 6拒绝加入群
            // 7 用户拒绝加入群 8用户请求加入群 9 管理员解散了群
            LogHelper.i("getGroup_uniq_id:"+centerMessageList.get(i).getGroup_uniq_id());
            if (centerMessageList.get(i).getType().equals("2") ||
                    centerMessageList.get(i).getType().equals("5") ||
                    centerMessageList.get(i).getType().equals("8")) {
                applyList.add(centerMessageList.get(i));
            }else {
                notifyList.add(centerMessageList.get(i));
            }
        }
        centerMessageList.clear();
        for (int i = 0; i < applyList.size(); i++) {
            if (0 == i) {
                applyList.get(i).setTypeFlag(0);
            }
            centerMessageList.add(applyList.get(i));
        }
        for (int i = 0; i < notifyList.size(); i++) {
            if (0 == i) {
                notifyList.get(i).setTypeFlag(1);
            }
            centerMessageList.add(notifyList.get(i));
        }
        applyListAdapter = new MessageListAdapter(getActivity(), centerMessageList);


        applyListView.setAdapter(applyListAdapter);
//        notifyListView.setAdapter(notifyListAdapter);
    }

    @Override
    @Click({R.id.back_btn})
    void Click(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                MainActivity.getFragmentMangerinstance().popBackStack();
                break;
           }

    }
}
